import { useModel } from "@umijs/max"
import { Button, Card, Input, Row, Select } from "antd"
import { useState } from "react"
import EapParamsForm from "./EapForms/EapParamsForm"
import PcSignalStatusForm from "./EapForms/PcSignalStatusForm"
import SizeLayoutForm from "./EapForms/SizeLayoutForm"
import PcDataCraftForm from "./EapForms/PcDataCraftForm"
import PcDataManualForm from "./EapForms/PcDataManualForm"
import PcDataAlarmForm from "./EapForms/PcDataAlarmForm"
import PcDataEmp from "./EapForms/PcDataEmp"
import PcDataStatusForm from "./EapForms/PcDataStatusForm"
import PcDataCount from "./EapForms/PcDataCount"

const EapTool = () => {
  const { callPy } = useModel("websocketModel")
  const [userId, setUserid] = useState<string>("")
  const [username, setUsername] = useState<string>("")
  const [empcode, setEmpcode] = useState<string>("上机时间")
  const [lotId, setLotId] = useState<string>("")

  const handleEmpReport = async () => {
    try {
      const response = await callPy("eh", "emp_report_from_web", [
        userId,
        username,
        empcode
      ])
      if (response.state) {
      }
    } catch (error) {
      console.log(error)
    }
  }

  const handleSendLotToEap = async () => {
    try {
      const response = await callPy("eh", "emp_report_from_web", [
        userId,
        username,
        empcode
      ])
      if (response.state) {
      }
    } catch (error) {
      console.log(error)
    }
  }

  return (
    <div>
      <Card>
        <Row>
          <div style={{ marginBottom: 8 }}>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              表轮询间隔设置
            </span>
            <span style={{ marginLeft: 10 }}>员工工号:</span>
            <Input
              value={userId}
              style={{ width: 100 }}
              onChange={(e) => setUserid(e.target.value)}
            />
            <span style={{ marginLeft: 10 }}>员工姓名:</span>
            <Input
              value={username}
              onChange={(e) => setUsername(e.target.value)}
              style={{ width: 100 }}
            />
            <span style={{ marginLeft: 10 }}>操作类型:</span>
            <Select
              style={{ width: 100, marginLeft: 10, marginRight: 10 }}
              defaultValue={empcode}
              onChange={(value) => setEmpcode(value)}
            >
              <Select.Option value="上机时间">上机时间</Select.Option>
              <Select.Option value="下机时间">下机时间</Select.Option>
            </Select>
            <Button onClick={handleEmpReport} type="primary">
              上下机上报
            </Button>

            <span style={{ marginLeft: 50, color: "#4169E1", fontSize: 18 }}>
              扫码工单:
            </span>
            <Input
              value={lotId}
              onChange={(e) => {
                setLotId(e.target.value)
              }}
              style={{ width: 250, marginLeft: 10, marginRight: 10 }}
            />
            <Button onClick={handleSendLotToEap} type="primary">
              扫码下发到Eap
            </Button>
          </div>
        </Row>
        <EapParamsForm />
        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              排板数量和排板方式配置表
            </span>
          </div>
        </Row>
        <SizeLayoutForm />

        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              工艺质量表(pc_data_craft)
            </span>
          </div>
        </Row>
        <PcDataCraftForm />

        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              手动参数调整表(pc_data_manualmaterial)
            </span>
          </div>
        </Row>
        <PcDataManualForm />

        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              设备报警表(pc_data_alarm)
            </span>
          </div>
        </Row>
        <PcDataAlarmForm />
        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              员工上下机记录上传(pc_data_emp)
            </span>
          </div>
        </Row>
        <PcDataEmp />

        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              不实时采集设备状态表(pc_data_status)
            </span>
          </div>
        </Row>
        <PcDataStatusForm />

        <Row style={{ marginTop: 8, marginBottom: 8 }}>
          <div>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              设备计数表(pc_data_count)
            </span>
          </div>
        </Row>
        <PcDataCount />

        <Row>
          <div style={{ marginTop: 8, marginBottom: 8 }}>
            <span style={{ color: "green", fontWeight: "bold", fontSize: 18 }}>
              设备实时信号表(pc_signal_status)
            </span>
          </div>
        </Row>
        <PcSignalStatusForm />
      </Card>
    </div>
  )
}

export default EapTool
